import 'package:flutter/material.dart';

extension PushAndPop on NavigatorState {
  Future<T?> pushAndRemoveRoutes<T extends Object?>(
    Route<T> newRoute,
    List<String>? routeNames,
  ) {
    if (routeNames != null && routeNames.isNotEmpty) {
      return pushAndRemoveUntil(
        newRoute,
        (route) => !routeNames.contains(route.settings.name),
      );
    }

    return push(newRoute);
  }
}
